﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DHQGHN.DAL.Common;
using DHQGHN.DAL.DAO.Admin;
using DHQGHN.DAL.Models.Admin;

namespace DHQGHN.DAL.BO.Admin
{
    public class OccupationBO : BaseBO
    {
        public const string FIELD_OCCUPATION_ID = "OCCUPATION_ID";
        public const string FIELD_NAME = "NAME";
        public const string FIELD_CODE = "CODE";
        public const string FIELD_LEVEL = "LEVEL";
        public const string FIELD_PARENT = "PARENT";
        public const string FIELD_PARENT_NAME = "PARENT_NAME";
        public const string FIELD_DESCRIPTIONS = "DESCRIPTIONS";
        public const string FIELD_DELETED = "DELETED";
        public const string FIELD_RECORD_COUNT = "RecordCount";

        private String _connectionString;

        public OccupationBO(string connString)
        {
            this._connectionString = connString;

        }
        public OccupationBO()
        {
            this._connectionString = Common.ConnectionUtil.TKTHDS_METADATA_CONNECTION_STRING;

        }

        public OccupationDAO _OccupationDAO;

        public OccupationDAO CreateSQLDAO()
        {
            return new OccupationDAO(_connectionString, DEFAULT_MAPPER_TYPE);
        }

        public DataPage<OccupationModel> GetDynamicListPaging(OccupationModel oModel, int pageSize, int pageIndex)
        {
            try
            {
                _OccupationDAO = CreateSQLDAO();
                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {
                    {OccupationModel.FIELD_OCCUPATION_ID,FIELD_OCCUPATION_ID},
                    {OccupationModel.FIELD_NAME,FIELD_NAME},
                    {OccupationModel.FIELD_CODE,FIELD_CODE},
                    {OccupationModel.FIELD_LEVEL,FIELD_LEVEL},
                    {OccupationModel.FIELD_PARENT,FIELD_PARENT},
                    {OccupationModel.FIELD_PARENT_NAME,FIELD_PARENT_NAME},
                    {OccupationModel.FIELD_DESCRIPTIONS,FIELD_DESCRIPTIONS},
                    {OccupationModel.FIELD_DELETED,FIELD_DELETED},
                    {OccupationModel.FIELD_RECORD_COUNT,FIELD_RECORD_COUNT}
                    
                };
                return _OccupationDAO.GetDynamicListPaging(oModel, pageSize, pageIndex, mapDictionary);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public OccupationModel GetOcById(string occupation_Id)
        {
            try
            {
                _OccupationDAO = CreateSQLDAO();

                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {
                    {OccupationModel.FIELD_OCCUPATION_ID,FIELD_OCCUPATION_ID},
                    {OccupationModel.FIELD_NAME,FIELD_NAME},
                    {OccupationModel.FIELD_CODE,FIELD_CODE},
                    {OccupationModel.FIELD_LEVEL,FIELD_LEVEL},
                    {OccupationModel.FIELD_PARENT_NAME,FIELD_PARENT_NAME},
                    {OccupationModel.FIELD_PARENT,FIELD_PARENT},
                    {OccupationModel.FIELD_DESCRIPTIONS,FIELD_DESCRIPTIONS},
                    {OccupationModel.FIELD_DELETED,FIELD_DELETED}
                    
                };

                return _OccupationDAO.GetById(occupation_Id, mapDictionary);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public bool createOrUpdateOccupation(OccupationModel ocModel)
        {
            try
            {
                _OccupationDAO = CreateSQLDAO();
                return _OccupationDAO.createOrUpdateOccupation(ocModel);
            }
            catch (Exception e)
            {
                return false;
            }
        }

        public bool deleteOccupation(string[] occupation_Id)
        {
            try
            {
                _OccupationDAO = CreateSQLDAO();
                return _OccupationDAO.deleteOccupation(occupation_Id);
            }
            catch (Exception e)
            {
                return false;
            }
        }

        public List<OccupationModel> GetAll()
        {
            try
            {
                _OccupationDAO = CreateSQLDAO();
                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {
                    {OccupationModel.FIELD_CODE,FIELD_CODE},
                    {OccupationModel.FIELD_NAME,FIELD_NAME}                    
                };
                return _OccupationDAO.GetAll(mapDictionary);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
